package ma.ensias.healthme;

import ma.ensias.healthme.admin.GestActivity;
import ma.ensias.healthme.dao.PersonneDao;
import ma.ensias.healthme.entities.Personne;
import ma.ensias.healthme.gerant.GestMaladieActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LogOnActivity extends Activity {
	Button logon;
	String log;
	String pass;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.log_on);
logon=(Button)findViewById(R.id.logOn);
		
		logon.setOnClickListener(new LogOnListener(this));
		
	}


}
class LogOnListener implements OnClickListener{

	Activity ac;
	String log;
	String pass;
	public LogOnListener(Activity ac){
		this.ac=ac;
		this.pass=pass;
		this.log=log;
	}
	@Override
	public void onClick(View arg0) {
		
		EditText login=(EditText)ac.findViewById(R.id.LoginFirst);
		EditText passW=(EditText)ac.findViewById(R.id.PassFirst);;
		
		log=login.getText().toString();
		pass=passW.getText().toString();
		//System.out.println(log+" "+pass);
		
		Intent i = null;
		Personne p=new PersonneDao().connexion(log, pass);
		if(p==null){
			Toast.makeText(ac, "Mot de passe ou login incorrect!", Toast.LENGTH_SHORT).show();
		}
		else{
			if(p.getRole().equals("Administrateur")){
				i=new Intent(ac,GestActivity.class);
			}
			else
				i=new Intent(ac,GestMaladieActivity.class);
			
			
			ac.startActivity(i);
			
		} 
		
		ac.finish();
	}
}